  // 车险 开始支付
import Vue from 'vue'
import {store} from '@/store/index'
import carPriceListMods  from '@/components/ivew_conf/car_price_list_mods'
import carPriceList  from '@/components/ivew_components/car_price_list/index.vue'
import { deepCopy } from '@/utils/tools';

import commonFn from './common_fn.ts'
  
let vueObj:any = new Vue();
const  pay = {

    title: '开始支付',
    icon: 'icon-also-loan',
    pag: 'pay',
    fn (){
        let orderData = store.state['carFormStore']['orderData'];
    
        let priceData = {
            jqPrice: orderData.SDjqAmount,
            syPrice: orderData.SDsyAmount,
            tax: orderData.SDtaxAmount,
            payment: orderData.SDpaidMethod,
            qrCodeUrl: orderData.SDqrCodeUrl,
            posCode: orderData.SDposCode,
            payId: orderData.SDpayId,
            payCertificateUrl: orderData.SDpayCertificateUrl
        }

        // 禁用
        let mods = deepCopy(carPriceListMods(true));
        mods.forEach(mod =>{
            mod.conf.disabled =  true;
        })


        // 值判断
        if(orderData.SDjqAmount === undefined){
            throw 'jqAmount is undefind'
        }
        
        vueObj.$Modal.confirm(
            {   
                onOk (){

                    let cache = JSON.stringify(priceData);

                    // 凭证验证
                    if(!priceData.payCertificateUrl){

                        vueObj.$Notice.warning({
                            title: '请提交支付凭证'
                        })

                        return
                    }
                    
                    // 修改订单状态
                    store.dispatch('request', {
                        url: 'patch/order/id/status',
                        data: {
                            // 修改流程,
                            currentAction: '转账',
                            payCertificateUrl: priceData.payCertificateUrl
                        }
                    }).then(success =>{
                        if(success){

                            vueObj.$Notice.success({
                                title: '支付成功'
                            })
                            
                             // 返回管理页
                             setTimeout(() =>{
                                commonFn('updateTable','outForm')
                            }, 500)
                        }
                    })
                    
                },
                render (h){
                    return h(carPriceList, {
                        props:{
                            data: priceData,
                            hasPayment: true,
                            hasVoucher: true,
                            paymentDisabled: true,
                            current: 'voucher',
                            mods,
                        }
                    })
                }            
            }
        )
        
    }

}

export default pay